Xbasic

ON_DATABASE_EXIT Function

Syntax

C on_database_exit(C code )

Arguments

code

A character string containing lines of Xbasic to be executed.

Description

Registers code to be executed when the current database is closed

Discussion

The ON_DATABASE_EXIT() function allows you to "register" code that will be executed when the current database is closed. You can call the function as many times as you want to register as many different code snippets as you want. To delete any code that was previously registered, but is no longer wanted, use the SYSTEM_EVENT_DROP("database_exit", name) command, where name is the sub-property of the p.database_exit variable returned by a call to the SYSTEM_EVENT_DATA_GET()function The usage of CAN_DATABASE_EXIT() is similar to ON_DATABASE_EXIT(). However, the code that is executed must issue a CANCEL()command in order to prevent the database from closing.

Example

Code = %code%
ui_msg_box("Notice", "The database about to close - First warning")
%code%
can_database_exit(code)
Code2 = %code%
ui_msg_box("Notice", "The database is now closing - Second warning")
%code%
on_database_exit(code2)

When you close the database, the scripts will be executed, and you will see two message boxes. To see what code has been registered to run:

dim ptr as P
ptr = system_event_data_get()
? ptr.database_exit

Note : You can use the ON_DATABASE_EXIT() function to register a ONESTEP_BACKUP()command.

dim cmd as C
cmd = "ui_msg_box(\"Backing up\",\"\");"
cmd = cmd + "onestep_backup() ;"
cmd = cmd + "a5.close() "
on_database_exit(cmd)

Limitations

Desktop applications only.

See Also